<?php
$groups = $_POST["groups"];
$channel = $_POST['channel'];
$uid = $_POST['uid'];
$historyId = $_POST['historyId'];
$unicomMallUid = $_POST['unicomMallUid'];
$referer = $_POST['referer'];
$pageKey = $_POST['pageKey'];
include_once("../../untils/conn.php");
if ($con) {
    mysqli_query($con, "set names utf8");
    $result = $con->query("SELECT * FROM config_api WHERE groups = '" . $groups . "'");
    if ($result->num_rows == 0) {
        // 数据库中不存在该记录，执行插入操作
        $data = $con->query("INSERT INTO config_api (groups, channel, uid, historyId, unicomMallUid, referer, pageKey) VALUES ('" . $groups . "', '" . $channel . "', '" . $uid . "', '" . $historyId . "', '" . $unicomMallUid . "' , '" . $referer . "', '" . $pageKey . "')");
        if ($data) {
            echo "<script>alert('添加信息');window.location.href='../ltapi.php'</script>";
        } else {
            echo ("<script>alert('添加失败');window.location.replace(document.referrer)</script>");
        }
    } else {
        // 数据库中存在该记录，执行更新操作
        $data = $con->query("UPDATE config_api SET channel = '" . $channel . "', uid = '" . $uid . "', historyId = '" . $historyId . "', unicomMallUid = '" . $unicomMallUid . "', referer = '" . $referer . "',  pageKey = '" . $pageKey . "'  WHERE groups = '" . $groups . "'");
        if ($data) {
            echo "<script>alert('修改信息成功');window.location.href='../ltapi.php'</script>";
        } else {
            echo ("<script>alert('修改失败');window.location.replace(document.referrer)</script>");
        }
    }
}

$con->close();
?>
